import 'package:flutter/material.dart';
import 'package:p_location/common/constant/color_list.dart';
import 'package:p_location/map/res/search_person_detail.dart';
import 'package:p_location/utils/string_util.dart';

class SearchPersonItem extends StatelessWidget {
  final bool isRealTime;

  final SearchPersonDetail detail;

  final Function callback;

  SearchPersonItem(this.isRealTime, this.detail, this.callback);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        if (_isValid()) {
          callback();
        }
      },
      child: Container(
        color: Colors.white,
        height: 45,
        child: Row(
          children: [
            IconButton(
              onPressed: () {},
              icon: Icon(Icons.circle),
              iconSize: 12,
              color: detail.online ? Colors.green : ColorList.RED,
            ),
            Container(
              width: 110,
              margin: EdgeInsets.only(left: 5, right: 15),
              child: Text(
                detail.name,
                style: TextStyle(color: _getTextColor()),
              ),
            ),
            Text(detail.sn, style: TextStyle(color: _getTextColor()))
          ],
        ),
      ),
    );
  }

  _isValid() {
    if (isRealTime && !detail.online) {
      return false;
    }
    if(StringUtil.isEmpty(detail.sn)){
      return false;
    }
    return true;
  }

  _getTextColor() {
    if (!_isValid()) {
      return ColorList.BLACK_45;
    }
    return Colors.black;
  }
}
